// spu接口
import request from '@/utils/request'
import type { SkuInfoData, ns, SkuData, HasSpuResponseData , AllTrademark, SpuImageResponse, SaleAttrResponseData, HasSaleAttrResponseData, SpuData} from './type'

enum API {
  // 获取spu接口
  HASSPU_URL = '/admin/product/',
  // 获取全部品牌的数据
  ALLTRADEMARK_URL = '/admin/product/baseTrademark/getTrademarkList',
  // 获取spu下的图片列表
  IMAGE_URL = '/admin/product/spuImageList/',
  // 获取spu下的销售属性
  SALEATTR_URL = '/admin/product/spuSaleAttrList/',
  // 获取整个项目全部的销售属性[颜色,版本,尺码]
  ALLSALEATTR_URL = '/admin/product/baseSaleAttrList',
  // 添加新spu
  ADDSPU_URL = '/admin/product/saveSpuInfo',
  // 更新spu
  UPDATESPU_URL = '/admin/product/updateSpuInfo',
  // 追加sku
  ADDSKU_URL = '/admin/product/saveSkuInfo',
  // 查看spu下的全部sku(售卖商品)
  SKUINFO_URL = '/admin/product/findBySpuId/',
  // 删除spu
  REMOVESPU_URL = '/admin/product/deleteSpu/'
}

// 5个接口加起来才是一个完整的spu


// 获取spu接口
export const reqHasSpu = (page:number, limit: number, category3Id: string|number) => request.get<any, HasSpuResponseData>(API.HASSPU_URL+`${page}/${limit}?category3Id=${category3Id}`)

// 获取全部品牌的数据
export const reqAllTrademark = () => request.get<any,AllTrademark>(API.ALLTRADEMARK_URL)

// 获取spu图片列表
export const reqSpuImageList = (spuId: number) => request.get<any,SpuImageResponse>(API.IMAGE_URL+`${spuId}`)

// 获取spu下销售属性
export const reqSaleAttrList = (spuId: number) => request.get<any, SaleAttrResponseData>(API.SALEATTR_URL+`${spuId}`)

// 获取全部的销售属性
export const reqAllSaleAttr = () => request.get<any,HasSaleAttrResponseData>(API.ALLSALEATTR_URL)

// 添加或修改spu
export const addOrUpdateSpu = (data: SpuData) => {
  if(data.id) {
    return request.post<any,any>(API.UPDATESPU_URL, data)
  } else {
    return request.post<any,any>(API.ADDSPU_URL, data)
  }
}

// 添加sku
export const reqAddSku = (data:SkuData) => request.post<any,any>(API.ADDSKU_URL, data)


// 获取sku数据
export const reqSkuList = (spuId: ns) => request.get<any, SkuInfoData>(API.SKUINFO_URL+`${spuId}`)

// 删除sku
export const reqRemoveSpu = (spuId: ns) => request.delete<any,any>(API.REMOVESPU_URL+`${spuId}`)





